﻿// News Framework
// (C) Tanzim Saqib. Oct 25, 2010.
// http://TanzimSaqib.com | http://newsfx.codeplex.com

using System.Windows.Controls;
using Microsoft.Phone.Controls;

namespace TanzimSaqib.NewsFramework
{
    using System.Windows.Media;
    using System.Windows;
    using System;
    using System.Windows.Media.Imaging;

    internal enum PhoneBackground
    {
        Dark,
        Light
    }

    internal sealed class PhoneUI
    {
        public static PhoneBackground CurrentPhoneBackground 
        { 
            get
            {
                return Application.Current.Resources["PhoneBackgroundColor"].ToString() == "#FF000000"
                           ? PhoneBackground.Dark
                           : PhoneBackground.Light;
            }
        }

        public static ImageBrush GetBackgroundBrush()
        {
            return new ImageBrush()
            {
                ImageSource = new BitmapImage(
                    new Uri(CurrentPhoneBackground == PhoneBackground.Dark
                                ? Fx.Instance.Settings[FxConstants.DarkThemeBackground]
                                : Fx.Instance.Settings[FxConstants.LightThemeBackground],
                            UriKind.Relative))
            };
        }

        public static void ConstructPage(Page page)
        {
            var phoneAppPage = (page as PhoneApplicationPage);

            switch (Fx.Instance.Settings[FxConstants.PageOrientation])
            {
                case "Landscape":
                    phoneAppPage.SupportedOrientations = SupportedPageOrientation.Landscape;
                    break;

                case "Portrait":
                    phoneAppPage.SupportedOrientations = SupportedPageOrientation.Portrait;
                    break;

                default:
                    phoneAppPage.SupportedOrientations = SupportedPageOrientation.PortraitOrLandscape;
                    break;
            }
        }
    }
}
